/*
 * @Description: 
 * @Date: 2022-10-17 18:13:41
 * @LastEditTime: 2022-10-18 10:12:10
 * @FilePath: /测试文档(总结)/49.ceshi.js
 * @Author: softbank126010077018.bbtec.net
 */
const count = [
  { countName: "养老设施专项规划修编", countNumber: 1, geometry: {} },
  { countName: "养老设施专项规划修编", countNumber: 1, geometry: {} },
  { countName: "养老设施专项规划修编", countNumber: 1, geometry: {} }
]
console.log(compare(count,"countName","countNumber"));
var list=[{
  price:1000,
  amount:1
},{
  price:1500,
  amount:3
},{
  price:1000,
  amount:1
},{
  price:1200,
  amount:2
},{
  price:1500,
  amount:3
},{
  price:1000,
  amount:1
}];
console.log('处理结果：',compare(list,'price','amount'));
//合并数组对象，相同key键的某一项数组求和
//arr：数组，judgeKey：判断的键,mergeKey：求和的键
function compare(arr,judgeKey,mergeKey){
  let result=[];
  arr.forEach(item=>{
      let index=-1;
      result.forEach((m,n)=>{
          if(m[judgeKey]==item[judgeKey]){
              index=n;
          }
      });
      if(index!=-1){
          result[index][mergeKey]+=item[mergeKey];
      }else{
          result.push(item);
      }
  });
  return result;
}